package tnp;

import java.lang.reflect.InvocationTargetException;

import org.apache.wicket.Page;
import org.apache.wicket.Response;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.http.WebRequest;
import org.apache.wicket.protocol.http.WebRequestCycle;

/**
 * TnpRequestCycle
 *
 */
public class TnpRequestCycle extends WebRequestCycle {

	public TnpRequestCycle(WebApplication application, WebRequest request,
			Response response) 
	{
		super(application, request, response);
	}

	@Override
	public Page onRuntimeException(Page page, RuntimeException e) 
	{
		Throwable t;
		if (e.getCause() instanceof InvocationTargetException) 
		{
			InvocationTargetException ite = (InvocationTargetException) e.getCause();
			t = ite.getTargetException();
		} 
		else 
		{
			if (e.getCause() == null) 
			{
				t = e;
			} 
			else 
			{
				t = e.getCause();
			}
		}
		setRedirect(true);
		return super.onRuntimeException(page, e);
	}

}
